package com.talent.web.model;

import com.talent.web.enums.ResponseEnum;
import com.talent.web.enums.TalentResponse;
/**
 * @ClassName：ResponseEnum
 * @Author: hszhou
 * @Date: 2024/10/21 13:35
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class TalentResult<T>{


    private int code;
    private String message;
    private T data;
    private boolean success;

    public TalentResult(){
    }

    public TalentResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    /**
     * 成功
     */
    public static <T> TalentResult<T> success() {
        return success(null);
    }

    /**
     * 成功
     */
    public static <T> TalentResult<T> success(T data) {
        TalentResult<T> responseResult = new TalentResult<T>();
        responseResult.setCode(ResponseEnum.SUCCESS.getCode());
        responseResult.setMessage(ResponseEnum.SUCCESS.getMessage());
        responseResult.setSuccess(true);
        responseResult.setData(data);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(TalentResponse res) {
        TalentResult<T> responseResult = new TalentResult<T>();
        responseResult.setCode(res.getCode());
        responseResult.setMessage(res.getMessage());
        responseResult.setSuccess(false);
        responseResult.setData(null);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(Integer code, String message) {
        TalentResult<T> responseResult = new TalentResult<T>();
        responseResult.setCode(code);
        responseResult.setMessage(message);
        responseResult.setData(null);
        responseResult.setSuccess(false);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(String message) {
        TalentResult<T> responseResult = new TalentResult<T>();
        responseResult.setCode(ResponseEnum.ERROR.getCode());
        responseResult.setMessage(message);
        responseResult.setData(null);
        responseResult.setSuccess(false);


        return responseResult;

    }


}
